package com.nbicc.service.modular.dp.widget.service;

import com.nbicc.core.common.RequestPageObj;
import com.nbicc.core.common.ResponseUtil;
import com.nbicc.core.utils.ToolUtils;
import com.nbicc.db.modular.dp.widget.mapper.WidgetClassMapper;
import com.nbicc.db.modular.dp.widget.model.WidgetClass;
import com.nbicc.service.parent.serivce.BaseSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import java.util.Map;

/**
 * @Author: lilingyan
 */
@Service
public class WidgetClassService extends BaseSerivce{

    @Autowired
    private WidgetClassMapper widgetClassMapper;

    public ResponseEntity<ModelMap> selectById(String id) {
        return ResponseUtil.ok(widgetClassMapper.selectById(id));
    }

    public ResponseEntity<ModelMap> find(RequestPageObj<Map<String, Object>> requestPageObj) {
        setPageHelper(requestPageObj);
        return ResponseUtil.ok(widgetClassMapper.selectByObject(requestPageObj.getData()));
    }

    public ResponseEntity<ModelMap> insert(WidgetClass widgetClass) {
        String id = ToolUtils.generateUUID32();
        widgetClass.setId(id);
        widgetClassMapper.insert(widgetClass);
        return ResponseUtil.ok(widgetClass);
    }

    public ResponseEntity<ModelMap> updateById(WidgetClass widgetClass) {
        widgetClassMapper.updateById(widgetClass);
        return ResponseUtil.ok();
    }

    public ResponseEntity<ModelMap> deleteById(String id) {
        widgetClassMapper.deleteById(id);
        return ResponseUtil.ok();
    }

}
